package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.LoungeEntity;

/**
 * 休息室预约表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class LoungeProvider {

    /**
     * 增加Lounge
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertLounge(@Param("entity") LoungeEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" lounge ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" home_type_code ", " #{entity.homeTypeCode,jdbcType=SMALLINT} ");
                VALUES(" home_id ", " #{entity.homeId,jdbcType=INTEGER} ");
                VALUES(" appointment_in_time ", " #{entity.appointmentInTime,jdbcType=TIMESTAMP} ");
                VALUES(" appointment_out_time ", " #{entity.appointmentOutTime,jdbcType=TIMESTAMP} ");
                VALUES(" reality_in_time ", " #{entity.realityInTime,jdbcType=TIMESTAMP} ");
                VALUES(" reality_out_time ", " #{entity.realityOutTime,jdbcType=TIMESTAMP} ");
                VALUES(" process_state_code ", " #{entity.processStateCode,jdbcType=TINYINT} ");
                VALUES(" rule_number ", " #{entity.ruleNumber,jdbcType=DECIMAL} ");
                VALUES(" rule_unit ", " #{entity.ruleUnit,jdbcType=VARCHAR} ");
                VALUES(" rule_code ", " #{entity.ruleCode,jdbcType=VARCHAR} ");
                VALUES(" rule_remark ", " #{entity.ruleRemark} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" random_code ", " #{entity.randomCode,jdbcType=VARCHAR} ");
                VALUES(" charge_id ", " #{entity.chargeId,jdbcType=INTEGER} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改Lounge
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateLounge(@Param("entity") LoungeEntity entity) {
        return new SQL() {
            {
                UPDATE(" lounge ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" home_type_code = #{entity.homeTypeCode,jdbcType=SMALLINT} ");
                SET(" home_id = #{entity.homeId,jdbcType=INTEGER} ");
                SET(" appointment_in_time = #{entity.appointmentInTime,jdbcType=TIMESTAMP} ");
                SET(" appointment_out_time = #{entity.appointmentOutTime,jdbcType=TIMESTAMP} ");
                SET(" reality_in_time = #{entity.realityInTime,jdbcType=TIMESTAMP} ");
                SET(" reality_out_time = #{entity.realityOutTime,jdbcType=TIMESTAMP} ");
                SET(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");
                SET(" rule_number = #{entity.ruleNumber,jdbcType=DECIMAL} ");
                SET(" rule_unit = #{entity.ruleUnit,jdbcType=VARCHAR} ");
                SET(" rule_code = #{entity.ruleCode,jdbcType=VARCHAR} ");
                SET(" rule_remark = #{entity.ruleRemark} ");
                SET(" remark = #{entity.remark} ");
                SET(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                SET(" charge_id = #{entity.chargeId,jdbcType=INTEGER} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询Lounge列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listLounge(@Param("entity") LoungeEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,home_type_code,home_id,appointment_in_time,appointment_out_time,reality_in_time,reality_out_time,process_state_code,rule_number,rule_unit,rule_code,rule_remark,remark,random_code,charge_id,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" lounge ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getHomeTypeCode() != null) {
                    WHERE(" home_type_code = #{entity.homeTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getHomeId() != null) {
                    WHERE(" home_id = #{entity.homeId,jdbcType=INTEGER} ");
                }

                if (entity.getAppointmentInTime() != null) {
                    WHERE(" appointment_in_time = #{entity.appointmentInTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getAppointmentOutTime() != null) {
                    WHERE(" appointment_out_time = #{entity.appointmentOutTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getRealityInTime() != null) {
                    WHERE(" reality_in_time = #{entity.realityInTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getRealityOutTime() != null) {
                    WHERE(" reality_out_time = #{entity.realityOutTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getProcessStateCode() != null) {
                    WHERE(" process_state_code = #{entity.processStateCode,jdbcType=TINYINT} ");
                }

                if (entity.getRuleNumber() != null) {
                    WHERE(" rule_number = #{entity.ruleNumber,jdbcType=DECIMAL} ");
                }

                if (entity.getRuleUnit() != null) {
                    WHERE(" rule_unit = #{entity.ruleUnit,jdbcType=VARCHAR} ");
                }

                if (entity.getRuleCode() != null) {
                    WHERE(" rule_code = #{entity.ruleCode,jdbcType=VARCHAR} ");
                }

                if (entity.getRuleRemark() != null) {
                    WHERE(" rule_remark = #{entity.ruleRemark} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getRandomCode() != null) {
                    WHERE(" random_code = #{entity.randomCode,jdbcType=VARCHAR} ");
                }

                if (entity.getChargeId() != null) {
                    WHERE(" charge_id = #{entity.chargeId,jdbcType=INTEGER} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}